package xaj.scc.ast;

import java.util.List;

import polyglot.ast.ClassMember;
import polyglot.ast.Node;
import abc.aspectj.extension.AJClassBody_c;
import polyglot.util.CodeWriter;
import polyglot.util.CollectionUtil;
import polyglot.util.Position;
import polyglot.util.TypedList;
import polyglot.visit.NodeVisitor;
import polyglot.visit.PrettyPrinter;

public class SyntaxClassBody_c extends AJClassBody_c implements SyntaxClassBody {
	
	private NumberOfPasses numberOfPasses;
	private SyntaxDeclaration syntaxDeclaration;
	private OnWeaving onWeaving;
	
	public SyntaxClassBody_c(Position pos, NumberOfPasses n, SyntaxDeclaration s, List members) {
		super(pos, members);
		numberOfPasses = n;
		syntaxDeclaration = s;
	}
	
	public SyntaxClassBody_c(Position pos, NumberOfPasses n, SyntaxDeclaration s, OnWeaving o, List members) {
		super(pos, members);
		numberOfPasses = n;
		syntaxDeclaration = s;
		onWeaving = o;
	}	

	public NumberOfPasses getNumberOfPasses() {
		return numberOfPasses;
	}

	public SyntaxDeclaration getSyntaxDeclaration() {
		return syntaxDeclaration;
	}

	public OnWeaving getOnWeaving() {
		return onWeaving;
	}
	
	public SyntaxClassBody setNumberOfPasses(NumberOfPasses number) {
		SyntaxClassBody_c n = (SyntaxClassBody_c) copy();
		n.numberOfPasses = number;
		return n;
	}

	public SyntaxClassBody setSyntaxDeclaration(SyntaxDeclaration sd) {
		SyntaxClassBody_c n = (SyntaxClassBody_c) copy();
		n.syntaxDeclaration = sd;
		return n;
	}

	public SyntaxClassBody setOnWeaving(OnWeaving ow) {
		SyntaxClassBody_c n = (SyntaxClassBody_c) copy();
		n.onWeaving = ow;
		return n;
	}
	
	/*protected SyntaxClassBody_c reconstruct(NumberOfPasses n, SyntaxDeclaration s, List members) {
        if(this.numberOfPasses != n || this.syntaxDeclaration != s ||
        		!CollectionUtil.equals(members, this.members)) {
        	SyntaxClassBody_c node = (SyntaxClassBody_c) copy();
        	node.numberOfPasses = n;
        	node.syntaxDeclaration = s;
        	node.members = TypedList.copyAndCheck(members, ClassMember.class, true);
        	return node;
        }
        return this;
    }*/
	
	protected SyntaxClassBody_c reconstruct(NumberOfPasses n, SyntaxDeclaration s, OnWeaving o, List members) {
        if(this.numberOfPasses != n || this.syntaxDeclaration != s ||
        		this.onWeaving != o || !CollectionUtil.equals(members, this.members)) {
        	SyntaxClassBody_c node = (SyntaxClassBody_c) copy();
        	node.numberOfPasses = n;
        	node.syntaxDeclaration = s;
        	node.onWeaving = o;
        	node.members = TypedList.copyAndCheck(members, ClassMember.class, true);
        	return node;
        }
        return this;
    }
	
	public Node visitChildren(NodeVisitor v) {
		NumberOfPasses nop = (NumberOfPasses) this.numberOfPasses.visit(v);
		SyntaxDeclaration sd = (SyntaxDeclaration) this.syntaxDeclaration.visit(v);
		OnWeaving ow = (OnWeaving)this.onWeaving.visit(v);
		List members = visitList(this.members, v);
		//Node n = reconstruct(nop, sd, members);
		Node n = reconstruct(nop, sd, ow, members);
		return n;
	}
	
	public void prettyPrint(CodeWriter w, PrettyPrinter tr) {
		w.newline(4);
		w.begin(0);
		numberOfPasses.prettyPrint(w, tr);
		w.newline(0);
		syntaxDeclaration.prettyPrint(w, tr);
		w.newline(0);
		onWeaving.prettyPrint(w, tr);
		w.newline(0);
		w.end();
		for(Object o : members()) {
			ClassMember m = (ClassMember) o;
			w.newline();
			m.prettyPrint(w, tr);
		}
	}
	
	@Override
	public void accept(Visitor v) {
		v.visitSyntaxClassBody(this);
	}
	
}
